package com.ywl.controller;


import com.ywl.common.R;
import com.ywl.entity.Product;
import com.ywl.service.ProductService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ywl
 * @since 2022-08-26
 */
@RestController
@Api(tags = "产品相关接口")
public class ProductController {

    @Autowired
    private ProductService productService;

    @ApiOperation("热点商品接口")
    @GetMapping("/hotProduct")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "city", value = "城市",required = true)
    })
    @Cacheable(value = "hotProductCache",key = "'product_'+#city")
    public R<List<Product>> getHotProduct(String city) {
        List<Product> products = productService.getHotProduct(city);
        return R.success(products);
    }

    @ApiOperation("推荐商品接口")
    @GetMapping("/recommendation")
    @Cacheable(value = "recProductCache",key = "'product_'+#city")
    public R<List<Product>> getRecProduct(String city) {
        List<Product> products = productService.getRecProduct(city);
        return R.success(products);
    }
}

